package com.topi.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.topi.event.EventMonitor.EventType;

@Service
public class EventMonitorService {

	@Autowired
	private EventMonitorRepository repository;
	
	
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public void notifySalesForceConnectionFailure ( Exception e ) {		
		EventMonitor monitor = new EventMonitor();
		monitor.setEventType(EventType.CONNECTION_ERROR);
		monitor.setDescription(e.getLocalizedMessage());
		repository.save(monitor);
	}

	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public void notifyIntegrationError ( Exception e ) {		
		EventMonitor monitor = new EventMonitor();
		monitor.setEventType(EventType.INTEGRATION_ERROR);
		monitor.setDescription(e.getMessage());
		repository.save(monitor);
	}


	
	
}
